<?php
/**
* 参数配置后台 Controller
*
* 参数配置后台 Controller的注意及说明
* 以下use模块请不要互相伤害
*
* @author    xiecz <xiecz@yunys.com.cn>
* @copyright 2016 QuanZhouYunYiShang Inc.
*/
namespace App\Http\Controllers\Backstage;

use Illuminate\Routing\Controller;
use Response, Request;
use App\Services\Tool\GeneralTool;
use App\Services\Tool\DataBase\DB_MYSQL_XCZ as DB;

class ConfigController extends Controller{

    function apiConfig(){
        $input  = Request::all();
        $db = new DB('configs');
        $db->where(['name' => 'cert_is_vaild']);
        $result['cert_is_vaild'] = $db->first();
        $db->where(['name' => 'enable_chat'],1);
        $result['enable_chat'] = $db->first();
        $db->where(['name' => 'apply_withddraw_cycle'],1);
        $result['apply_withddraw_cycle'] = $db->first();
        $db->where(['name' => 'apply_withddraw_cycle_times'],1);
        $result['apply_withddraw_cycle_times'] = $db->first();
        $db->where(['name' => 'withdraw_poundage'],1);
        $result['withdraw_poundage'] = $db->first();
        $db->where(['name' => 'withdraw_max'],1);
        $result['withdraw_max'] = $db->first();
        $db->where(['name' => 'user_bank_card_max'],1);
        $result['user_bank_card_max'] = $db->first();
        // dd($result);
        return view('backstage.config.api-configs')->with('result',$result);
    }

    function updateApiCongfig(){
        $input  = Request::all();
        if(!isset($input['id']) || !isset($input['value'])) return response()->json(GeneralTool::createResult('','M00002'));

        $db = new DB('configs');
        $db->where(['id'    => $input['id'],
                    'state' => 1]);
        $result = $db->update(['value' => $input['value']]);
        return response()->json(GeneralTool::createResult('',($result ? 'M00000' : 'M00001')));
    }
}


